<?php

class email_userAction extends Controller {

    function index() {

        if (isset($_POST['dosubmit'])) {
            $this->load->model('email_users_model');
            $email = $this->input->post('email');
            $csign = $this->input->post('sign');
            $type = $types = $this->input->post('type', TRUE);
            $arr = explode("\n", $email);
            $arr = array_filter($arr);
            foreach ($arr as $v) {
                $val = explode($csign, $v);
                if ($types == 'auto') {
                    $sql['email_users_content'] = '';
                    $sql['email_users_status'] = '1';
                    preg_match("/.*@([0-9a-zA-Z]*)\.(.*)/is", $val[0], $m);
                    $type = isset($m[1]) ? $m[1] : 'err';
                    if ($type == 'fatung') {
                        switch ($m[2]) {
                            case 'com':
                                $type = 'gmail';
                                break;
                            case 'org':
                                $type = 'qq';
                                break;
                            default :
                                $type = 'err';
                                $sql['email_users_content'] = '邮箱地址错误，请修改核对';
                                $sql['email_users_status'] = 0;
                                break;
                        }
                    }
                    if (!isset($m[1])) {
                        $sql['email_users_content'] = '邮箱地址错误，请修改核对';
                        $sql['email_users_status'] = 0;
                    }
                }
                $sql['email_users_type'] = $type;
                $sql['email_users_name'] = $val[0];
                $sql['email_users_pass'] = $val[1];
                $this->email_users_model->insert_email_users($sql);
            }
        }
        
        $this->load->model('email_post_user_model');

        $data['x'] = $this->email_post_user_model->get_email_post_user_list(array());

        $this->load->layout('email/email_user', $data);
    }

}

?>